Ext.define('IHC.controller.ihc.cadastros.IHC001ListController', {
    extend : 'Ext.app.Controller',
    
    requires : [
        'IHC.model.Projeto', 
        'IHC.store.ihc.cadastros.IHC001Projeto', 
        'IHC.view.ihc.cadastros.IHC001ListView',
        'IHC.view.ihc.cadastros.IHC001MasterListView',
        'IHC.view.ihc.cadastros.IHC001DetailListView',
        'IHC.view.ihc.IHC001HelpWindow'
    ],
    
    stores : [
        'IHC.store.ihc.cadastros.IHC001Projeto',
        'IHC.store.ihc.cadastros.IHC001Atividade'
    ],
    
    models : [
        'IHC.model.Projeto'
    ],
    
    views : [
        'IHC.view.ihc.cadastros.IHC001ListView',
        'IHC.view.ihc.cadastros.IHC001MasterListView',
        'IHC.view.ihc.cadastros.IHC001DetailListView',
        'IHC.view.ihc.IHC001HelpWindow'
    ],
    
    formModule : 'IHC.controller.ihc.cadastros',
    
    formName : 'IHC001',
    
    suffixName : '',
    
    mixins : [
        'InsoftExtUi.ux.mixins.controller.CrudMasterListMixin'
    ],
    
    refs : [{
        selector : 'ihc001-list',
        xtype : 'ihc001-list',
        ref : 'principal',
        autoCreate : true
    }, {
        selector : 'ihc001-master-list',
        xtype : 'ihc001-master-list',
        ref : 'mainGrid',
        autoCreate : true
    }],
    
    init : function() {
        var me = this;
    
        if (!me.inited) {
            me.bindDefaultActions('#ihc001-master-list');
            me.recordStore = me.getStore('IHC.store.ihc.cadastros.IHC001Projeto');
        }

        me.control({
            '#ihc001-master-list' : {
                selectionchange : me.onSelectionChange
            },
            "#ihc001-list button[action=helpRecord]" : {
            	click : me.helpProjeto
            }
        });

        me.inited = true;
    },

    actionIndex : function() {
        var me = this, manager = me.getLocaleManager(), title = manager.get('ihc001.mainPanel.title');
        me.recordStore.load();
        me.application.addTab(this.getPrincipal(), 'IHC001', title);
        manager.applyLocalesFor('#IHC001Tab');
        me.application.runAction('IHC.controller.ihc.cadastros.IHC001DetailListController', 'Index');
    },

    getDetailInfo : function() {
        var me = this, 
            controller = me.getController('IHC.controller.ihc.cadastros.IHC001DetailListController');
        return {
            grid : controller.getMainGrid(),
            filterName : 'projetoFilter'
        };
    },

    onSelectionChange : function(model, selected, eOpts) {
        this.masterRecordChanged(selected[0]);
    },
    
    helpProjeto : function() {
    	var me = this,
    		window = me.getView('IHC.view.ihc.IHC001HelpWindow').create();
    	
    	window.show();
    }
});
